﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace DesktopGarden.Windows
{
    /// <summary>
    /// Interaction logic for GardenEditor.xaml
    /// </summary>
    public partial class GardenEditor : Window
    {
        public Garden SelectedGarden { get; set; }
        public GardenEditor(Garden garden, string title)
        {
            InitializeComponent();
            this.Title = title;
            lbl_Name.Content = title;
            SelectedGarden = garden;
            this.DataContext = SelectedGarden;
        }

        private void ClickBrowse(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.FileName = SelectedGarden.GardenName;
            saveFile.Filter = "Garden Files (*.gdn)|*.gdn";

            if (Properties.Settings.Default.LastSaveLocation != null)
                saveFile.InitialDirectory = Properties.Settings.Default.LastSaveLocation;
            if ((bool)saveFile.ShowDialog())
            {
                SelectedGarden.SaveLocation = saveFile.FileName;
                txtSaveLoc.Text = SelectedGarden.SaveLocation;
            }
        }

        private void ClickSave(object sender, RoutedEventArgs e)
        {
            if (SelectedGarden.SaveLocation == null)
            {
                MessageBox.Show("Please enter a save location.");
            }
            else
            {
                Properties.Settings.Default.LastSaveLocation = SelectedGarden.SaveLocation;
                Properties.Settings.Default.Save();
                this.DialogResult = true;
            }
        }

        private void ClickCancel(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
